/*
 * Copyright (C) 2009 Internal Innovation Technology(IIT)
 * 
 */
package com.iitbd.hxcalc;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 *
 * @author Prasun Kanti Howlader <prasun@iitbd.com>
 */
public class Resources {

    private static final String BUNDLE_NAME = "resources.ResourceBundle";
    private static ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault());

    /**
     * Preventing direct instantiation
     *
     */
    private Resources() {
    }

    /**
     * Select the resource against the Local Language
     */
    public static void resourceInitialize() {
        RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault());
    }

    /**
     * Find the value of a given key.if no key found then return !key!
     * @param key
     * @return String value
     */
    public static String getString(String key) {
        try {
            return RESOURCE_BUNDLE.getString(key);
        } catch (MissingResourceException e) {
            return "!" + key + "!";
        }
    }

    public static String tr(String key) {
        return getString(key);
    }

    public static boolean hasTranslation(String key) {
        try {
            return RESOURCE_BUNDLE.containsKey(key);
        } catch (NullPointerException e) {
            return false;
        }
    }

    /**
     * Clear the current resource bundle and reload new resource bundle
     */
    public static void clearCache() {
        RESOURCE_BUNDLE.clearCache();
    }
}
